<template>
  <view class="container">
    <!-- 搜索栏 -->
    <view class="search-bar">
      <input
        class="search-input"
        type="text"
        v-model="searchKeyword"
        placeholder="搜索门店名称或地址"
        @confirm="handleSearch"
      />
      <view class="search-icon" @click="handleSearch">
        <text class="iconfont icon-search"></text>
      </view>
    </view>

    <!-- 门店列表 -->
    <view class="store-list">
      <view
        class="store-item"
        v-for="(store, index) in filteredStores"
        :key="index"
        @click="handleStoreClick(store)"
      >
        <image
          class="store-image"
          :src="store.image_url"
          mode="aspectFill"
        ></image>
        <view class="store-info">
          <view class="store-name">{{ store.name }}</view>
          <view class="store-address">{{ store.address }}</view>
          <view class="store-hours">{{ store.business_hours }}</view>
          <view class="store-distance" v-if="store.distance">
            距离您 {{ store.distance.toFixed(1) }}km
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      searchKeyword: "",
      stores: [
        {
          id: 1,
          name: "总店",
          address: "北京市朝阳区建国路88号",
          phone: "010-88888888",
          business_hours: "09:00-21:00",
          description: "中医馆总店，提供全面的中医诊疗服务",
          image_url: "/static/stores/store1.jpg",
          latitude: 39.9042,
          longitude: 116.4074,
          distance: 1.2,
        },
        {
          id: 2,
          name: "东城分店",
          address: "北京市东城区王府井大街1号",
          phone: "010-66666666",
          business_hours: "09:00-21:00",
          description: "东城区分店，交通便利，环境优雅",
          image_url: "/static/stores/store2.jpg",
          latitude: 39.915,
          longitude: 116.4037,
          distance: 2.5,
        },
        {
          id: 3,
          name: "西城分店",
          address: "北京市西城区西单北大街1号",
          phone: "010-77777777",
          business_hours: "09:00-21:00",
          description: "西城区分店，专业团队，服务周到",
          image_url: "/static/stores/store3.jpg",
          latitude: 39.9139,
          longitude: 116.3917,
          distance: 3.8,
        },
      ],
    };
  },
  computed: {
    filteredStores() {
      if (!this.searchKeyword) {
        return this.stores;
      }

      const keyword = this.searchKeyword.toLowerCase();
      return this.stores.filter(
        (store) =>
          store.name.toLowerCase().includes(keyword) ||
          store.address.toLowerCase().includes(keyword)
      );
    },
  },
  methods: {
    // 处理搜索
    handleSearch() {
      // 搜索逻辑已经在计算属性中实现
    },

    // 处理门店点击
    handleStoreClick(store) {
      uni.navigateTo({
        url: `/pages/store/detail?id=${store.id}`,
      });
    },
  },
};
</script>

<style>
.container {
  padding: 20rpx;
}

.search-bar {
  display: flex;
  align-items: center;
  background: #f5f5f5;
  border-radius: 40rpx;
  padding: 0 20rpx;
  margin-bottom: 20rpx;
}

.search-input {
  flex: 1;
  height: 80rpx;
  font-size: 28rpx;
}

.search-icon {
  padding: 0 20rpx;
}

.store-list {
  margin-top: 20rpx;
}

.store-item {
  display: flex;
  padding: 20rpx;
  background: #fff;
  border-radius: 10rpx;
  margin-bottom: 20rpx;
  box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
}

.store-image {
  width: 200rpx;
  height: 200rpx;
  border-radius: 10rpx;
  margin-right: 20rpx;
}

.store-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.store-name {
  font-size: 28rpx;
  font-weight: bold;
  margin-bottom: 10rpx;
}

.store-address {
  font-size: 24rpx;
  color: #666;
  margin-bottom: 10rpx;
}

.store-hours {
  font-size: 24rpx;
  color: #666;
  margin-bottom: 10rpx;
}

.store-distance {
  font-size: 24rpx;
  color: #007aff;
}
</style> 